part of '../repository.dart';

const _kCollectionSortingAlphabeticallyValue = 'alphabetically';
const _kCollectionSortingByFrequencyValue = 'by_frequency';
const _kCollectionSortingByLearningValue = 'by_learning';

class _CollectionSortingDto extends Equatable {
  const _CollectionSortingDto._internal({
    required this.sortingString,
  });

  final String sortingString;

  @override
  List<Object?> get props {
    return [
      sortingString,
    ];
  }

  factory _CollectionSortingDto.fromString(String sortingString) {
    return _CollectionSortingDto._internal(
      sortingString: sortingString,
    );
  }

  factory _CollectionSortingDto.fromEntity(CollectionSorting sorting) {
    final sortingString = switch (sorting) {
      CollectionSorting.alphabetically => _kCollectionSortingAlphabeticallyValue,
      CollectionSorting.byFrequency => _kCollectionSortingByFrequencyValue,
      CollectionSorting.byLearning => _kCollectionSortingByLearningValue,
    };

    return _CollectionSortingDto._internal(
      sortingString: sortingString,
    );
  }

  @override
  String toString() {
    return sortingString;
  }

  CollectionSorting toEntity() {
    return switch (sortingString) {
      _kCollectionSortingAlphabeticallyValue => CollectionSorting.alphabetically,
      _kCollectionSortingByFrequencyValue => CollectionSorting.byFrequency,
      _kCollectionSortingByLearningValue => CollectionSorting.byLearning,
      _ => throw UnimplementedError(),
    };
  }
}
